<?php

$app = [];
$app['config'] = require 'config.php'; 
require 'Core/DataBase/ConnetDB.php';
require 'Core/DataBase/RequestDB.php';

$pdo = ConnetDB::make($app['config']['database']);
$quesy = new RequestDB($pdo);

$gogo =null;

if(isset($_GET['admin'])){
	$gogo = $_GET['admin'];
}

$account = [];
$password = [];
if(isset($_POST['account']) and isset($_POST['password'])){
	$account = $_POST['account'];
	$password = md5($_POST['password']);
	$islogin = $quesy -> ToLogin($account,$password);
	if($islogin == null){
		echo "Fail";
	}elseif($islogin[0] != null){
		session_start();
		$_SESSION["account"] = $islogin[0]['userName'];
		$_SESSION["accountid"] = $islogin[0]['id'];
		$_SESSION["name"] = $islogin[0]['nickName'];
		$_SESSION["isloader"] = $islogin[0]['isupload'];
		$_SESSION["isadmin"] = $islogin[0]['isadmin'];
		
		if($gogo == "1"){
			Header('location:/panels');
		}else{
			Header('location:/videos?go=all');
		}
	}
}

require 'WebView/login.view.php';

?>